import { ajax } from '@/utils'

import type {
  GetCouponListTypeReq,
  GetCouponListTypeRes,
  GetPermissionRes,
  LoginRes
} from './commonTypes'

const baseUrl = '/yswy-zy-permission'

export default {
  login(data: Record<string, any>): Promise<LoginRes> {
    return ajax.post(`${baseUrl}/user/login`, data, {
      withToken: false
    })
  },
  logout(): Promise<void> {
    return ajax.post(`${baseUrl}/user/logout`)
  },
  /**
   * 获取用户权限
   * @param {string} userId 用户编号
   */
  getPermissions(userId: string): Promise<GetPermissionRes> {
    return ajax.get(`${baseUrl}/permission/getPermission`, {
      params: {
        userId
      }
    })
  },
  getCouponTypeList(
    params: GetCouponListTypeReq
  ): Promise<GetCouponListTypeRes> {
    return ajax.get('/yswy-zy-coupon-manage/couponManage/simpleList', {
      params
    })
  },
  /** 上传文件地址 */
  uploadFileUrl: import.meta.env.VITE_APP_API + '/yswy-zy-oss/oss/uploadFile'
}
